<?php

/**
 * @author yupoxiong<i@yufuping.com>
 */

namespace generate\field;

class KeyWords extends Field
{

    public static $html = <<<EOF
    <div class="form-group">
    <label for="[FIELD_NAME]" class="col-sm-2 control-label">关键词</label>
    <div class="col-sm-10 col-md-4">
        <input id="[FIELD_NAME]" name="[FIELD_NAME]" value="{\$data.[FIELD_NAME]|default='[FIELD_DEFAULT]'}"
            placeholder="请输入关键词" type="text" class="form-control field-text">
    </div>
</div>
<style type="text/css">
    .bor {
        border: none !important;
    }
</style>
<script>
    $('#[FIELD_NAME]').tagsinput('add', 'some tag');
    $(".bootstrap-tagsinput").addClass('col-sm-12').find('input').addClass(
            'form-control field-text bor')
        .attr('placeholder', '输入后按Enter');
</script>\n
EOF;

    public static $rules = [
        'required'   => '非空',
    ];

    public static function create($data)
    {

       return  str_replace(
            ['[FORM_NAME]', '[FIELD_NAME]', '[FIELD_DEFAULT]'],
            [$data['form_name'], $data['field_name'], $data['field_default']],
            self::$html);

    }

}